<?php
echo "account to user start<br/>";
include_once('config.inc.php');

$link=mysql_connect($hostname,$username,$password);

$status=mysql_select_db("vtigercrm520");

$query="SELECT accountid,cf_663 FROM vtiger_accountscf";

$aidKUIDquery=mysql_query($query, $link);

$K2vtUserMap=array(
742 => 13809,
1139 => 13810,
5044 => 13820,
6081 => 13821,
7051 => 13822,
8568 => 13811,
8681 => 13823,
8888 => 13812,
9348 => 13824,
11192 => 13813,
13633 => 13814,
14173 => 13825,
14481 => 13826,
17004 => 13827,
18679 => 13815,
18975 => 13816,
19590 => 13817,
20701 => 13828,
22098 => 13818,
23531 => 13819,
26701 => 13829,
27268 => 13830,
27713 => 13831,
30256 => 13832
);

if(!$aidKUIDquery) {
		print("Query Error: ".mysql_error());
	}

while($aidKUID=mysql_fetch_assoc($aidKUIDquery)) {
	print("Fetching accountid and KontaktID fields<br/>");
	$aid=$aidKUID['accountid'];
	$KUID=$aidKUID['cf_663'];
	$newuid=$K2vtUserMap[$KUID];
	if (!$KUID) {$newuid=13833;};
	$updatequery="UPDATE vtiger_crmentity SET smownerid = $newuid  WHERE crmid = $aid";
	print("performing update on record $aid to owner $newuid formerly $KUID<br/>");
	$execupdatequery=mysql_query($updatequery,$link);
   if(!$execupdatequery) {
		print("Query Error: ".mysql_error()."<br/>");
	}
}

print ("Done.<br/>");
?>